package mju.cxf.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import mju.cxf.constant.MessageConstant;
import mju.cxf.dto.ActivityDTO;
import mju.cxf.dto.MemberDTO;
import mju.cxf.result.Result;
import mju.cxf.service.MemberService;
import mju.cxf.vo.ActivityVO;
import mju.cxf.vo.MemberVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 会员相关接口
 */

@RestController
@RequestMapping("/admin/api/member")
@Api(tags = "会员接口列表")
public class MemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 新建会员信息
     *
     * @param memberDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新建会员")
    public Result<String> createMember(@RequestBody MemberDTO memberDTO) {
        return memberService.saveMember(memberDTO) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }

    /**
     * 修改会员信息
     *
     * @param memberDTO
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改会员信息")
    public Result<String> updateMember(@RequestBody MemberDTO memberDTO) {
        return memberService.updateMember(memberDTO) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }

    /**
     * 删除会员信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除会员信息", notes = "管理员通过此接口删除会员信息")
    public Result<String> deleteMember(@PathVariable Integer id) {
        return memberService.deleteMember(id) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }

    /**
     * 分页查询会员信息
     * @return 分页查询结果
     */
    @GetMapping("/pages")
    @ApiOperation(value = "分页查询会员信息", notes = "管理员通过此接口分页查询会员信息")
    public Page<MemberVO> selectPage(@RequestParam(value = "grade",required = false) Integer grade,
                                     @RequestParam(value = "current",defaultValue = "1") int current,
                                     @RequestParam(value = "size",defaultValue = "10") int size) {
        return memberService.selectPage(grade, current, size);
    }
}
